﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace InformationExtraction
{
    class Parser
    {
        public List<Page> Pages { get; private set; }

        public void Parse(string path, bool printProcess, int initialSize)
        {
            DateTime begin = DateTime.Now;

            if (printProcess)
                Utils.PrintProcessBegin("Reading data to memory & spliting to pages", "Lines");

            StreamReader file = File.OpenText(path);

            Pages = new List<Page>(initialSize);

            string line;
            string title = null;
            int i = 0;
            while((line = file.ReadLine()) != null)
            {
                if (!string.IsNullOrWhiteSpace(line))
                {
                    if (!line.Contains("/"))
                        title = line;
                    else
                        Pages.Add(new Page(title, line));
                }

                if (printProcess)
                    Utils.PrintProgress(++i);
            }

            file.Close();

            if (printProcess)
                Utils.PrintProcessEnd(begin, i);
        }
    }
}
